#ifndef PACKET_INFO_H_
#define PACKET_INFO_H_


#include "uthash.h"
#include "cope-packet.h"

/* this is the key of the hash table */
typedef struct {
    int pkt_id;
    int nodeid;
} info_key_t;

/* the real hash table entry */
typedef struct {
    info_key_t key;
    bool prob; 
    UT_hash_handle hh;
} packet_info_t;


class PacketInfo {
 public:
    PacketInfo();
    ~PacketInfo();

   
    /* get prob for a specific neighbor and pkt_id */
    bool get_prob(int nb, int pkt_id);  
 
    /* update packet info when receive a state report */
    void update_pkt_info(hdr_report_t, int);
    /* 
     * update packet info when receive a packet, which means
     * the previous hop will have the packets for sure
     */
    void update_pkt_info(Packet * p, int);
    
    void update_pkt_info(int pktid, int nodeid, bool prob);
    
    /*
     * get the number of pkts from start_seq to last_seq for src_ip,
     * this is mainly used by ProbGuess class
     */
    int get_pkt_count(int /* nb */,
		      nsaddr_t /* src_ip */,
		      uint16_t /* start_seq_num */, 
		      uint16_t /* last_seq_num */);

    //    int checkpktinfo(info_key_t key);
 private:
    /*
     * the packet info hash table to store the probability of
     * each neighbor having that pakcet
     */
    packet_info_t* pkt_info_table_;
    
    /*
     * Internal member functions
     */
    
    /* add a packet info entry */
    void add_pkt_info(int pktid, int nodeid, bool prob);
    
    /* find a pakcet info entry with key */
    packet_info_t* find_pkt_info(int pktid, int nodeid);
    
    /* delete a packet entry */
    void del_pkt_info(packet_info_t* delinfo);
    
    /* update a packet entry with new probability */
    void up_pkt_info(packet_info_t* oldinfo, bool newprob);
   
};

#endif
